<?php

class Controller_Album extends FLEA_Controller_Action
{
	
	var $smarty;
	
	function Controller_Album(){
		
		
		
	}	

	function actionView(){
		if (isset($_GET['id'])) {
            $albumId = (int)$_GET['id'];
        } else {
            redirect(url());
        }
		
		$tableAlbums = FLEA::getSingleton('Model_Albums');
		$album = $tableAlbums->_getAlbum($albumId);

		$this->smarty = &$this->_getView();
		$this->smarty->assign('album', $album);
		$this->smarty->assign('title', 'aGrindcore');
		$this->smarty->display('tpl_album.html');
	}

	function actionAdd(){
		
		if (!empty($_POST['albumName'])) {
			
			FLEA::loadHelper('uploader');
			$uploader =& new FLEA_Helper_FileUploader();
			if (!$uploader->isFileExist('albumCover')) {
				js_alert('请选择要上传的文件', '', url('album', 'add'));
			}
			// 检查上传文件的扩展名是否正确
			$postfile = $uploader->getFile('albumCover');
			if (!$postfile->check('.jpg/.png/.gif')) {
				js_alert('只允许上传 jpeg/gif/png 格式的文件', '', url('album', 'add'));
			}
			//dump($postfile);
            /*$data = array(
				'artist_id' => $_POST['artistId'],
				'album_name' => htmlspecialchars($_POST['albumName']),
				'release_date' => $_POST['releaseDate'],				
				'label_name' => htmlspecialchars($_POST['labelName'])

			);*/
			$tableAlbums = FLEA::getSingleton('Model_Albums');
						
			$tableAlbums->uploadPhoto($postfile);
			//$tableAlbums->create($data);
			
        } else {
            $this->smarty = &$this->_getView();		
			$this->smarty->display('tpl_album_add.html');
        }
		
	}

	
	
}
?>